﻿
using HuaCheng.DataAccess;
using HuaCheng.Model;
using HuaCheng.Views;
namespace HuaCheng.Controller
{
    public class CheckLogControl
    {
        /// <summary>
        /// 根据右键菜单所点击的项写入本地日志
        /// </summary>
        /// <param name="tsmiName"></param>
        public static void WriteToLocalLog(string tsmiName)
        {
            LocalLog localLog=null;
            switch (tsmiName)
            {
                case "tsmiSingleStart":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime=System.DateTime.Now,
                            Record="用户单点启动",
                            LocalEvent="右键点击单点启动"
                        };
                    }break;
                case "tsmiSingleStop":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "用户单点停止",
                            LocalEvent = "右键点击单点停止"
                        };
                    } break;
                case "tsmiSetParallel":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "设置并联",
                            LocalEvent = "设置/解除并联"
                        };
                    } break;
                case "tsmiContinue":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "工步接续",
                            LocalEvent = "接续"
                        };
                    } break;
                case "tsmiMove":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "工步迁移",
                            LocalEvent = "迁移"
                        };
                    } break;
                case "tsmiResetStep":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "重置工步",
                            LocalEvent = "重置工步"
                        };
                    } break;
                case "tsmiChannelCopy":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "通道复制",
                            LocalEvent = "通道复制"
                        };
                    } break;
                case "tsmiResetMap":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "设定中位机映射",
                            LocalEvent = "重置映射"
                        };
                    } break;
                case "tsmiChannelInfo":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "查看通道信息",
                            LocalEvent = "通道信息"
                        };
                    } break;
                case "tsmiUnitOrder":
                    {
                       localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "单位定制",
                            LocalEvent = "单位定制"
                        };
                    } break;
                case "tsmiCheckLog":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "查看日志",
                            LocalEvent = "查看日志"
                        };
                    } break;
                case "tsmiShutdown":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "关机",
                            LocalEvent = "关机"
                        };
                    } break;
                case "tsmiJump":
                    {
                        localLog = new LocalLog()
                        {
                            TestATime = System.DateTime.Now,
                            Record = "工步跳转",
                            LocalEvent = "跳转"
                        };
                    } break;
            }
            if (localLog != null)
            {
                TxtControl.WriteLocalLogToTxt(localLog);
            }
        }
        /// <summary>
        /// 写入设备日志
        /// </summary>
        /// <param name="unitId"></param>
        /// <param name="chlId"></param>
        public static void WriteToDeviceLog(string logName,int gid,int mid,int chlId)
        {
            string testId = StepHelper.GetTestIdById(IndexPage.devIp,gid,mid, chlId);
            DeviceLog deviceLog = new DeviceLog()
            {
                DevIp = IndexPage.devIp,
                MID = mid,
                GID = gid,
                ChlId = chlId,
                TestId = testId,
                TestATime = System.DateTime.Now,
                Operator=IndexPage.username
            };
            switch (logName)
            { 
                case "btnStart":
                    {
                        deviceLog.OperationType = "用户启动";
                    }break;
                case "testFinish":
                    {
                        deviceLog.OperationType = "测试完成";
                    }break;
                case "exit":
                    {
                        deviceLog.OperationType = "关闭程序";
                    } break;
                case "tsmiContinue":
                    {
                        deviceLog.OperationType = "接续";
                    } break;
                case "tsmiResetStep":
                    {
                        deviceLog.OperationType = "重置工步";
                    } break;
                case "tsmiSingleStop":
                    {
                        deviceLog.OperationType = "用户停止";
                    } break;
                case "tsmiMove":
                    {
                        deviceLog.OperationType = "迁移";
                    } break;
                case "tsmiDcir":
                    {
                        deviceLog.OperationType = "DCIR测试";
                    } break;
            }
            if (deviceLog != null)
            {
                DeviceLogHelper.InsertDeviceLog(deviceLog);
            }
        }
    }
}
